package 多态.instrumentExample;


class Instrument {
	void play() {
		System.out.println("play instrument");
	}

	;

	String what() {
		return "instrument";
	}

	void adjust() {
		System.out.println("adjust instrument");
	}
}

class Wind extends Instrument {
	@Override
	String what() {
		return "wind";
	}

	@Override
	void adjust() {
		System.out.println("adjust wind ");
	}

	@Override
	void play() {
		System.out.println("wind play");
	}
}

class Percussion extends Instrument {
	@Override
	void play() {
		System.out.println("play percussion");
	}

	@Override
	String what() {
		return "percussion";
	}

	@Override
	void adjust() {
		System.out.println("adjust percussion");
	}
}

class Stringed extends Instrument {
	@Override
	void play() {
		System.out.println("play stringed");
	}

	@Override
	String what() {
		return "stringed";
	}

	@Override
	void adjust() {
		System.out.println("adjust stringed");
	}
}

class WoodWind extends Wind {
	@Override
	String what() {
		return "WoodWind";
	}

	@Override
	void adjust() {
		System.out.println("adjust woodWind");
	}

	@Override
	void play() {
		System.out.println("play woodWind");
	}
}

class Brass extends Wind {
	@Override
	String what() {
		return "brass";
	}

	@Override
	void adjust() {
		System.out.println("adjust brass");
	}

	@Override
	void play() {
		System.out.println("play brass");
	}
}

public class Music3 {
	public static void main(String[] args) {
		Instrument[] instruments = {
				new Wind(),
				new Percussion(),
				new Stringed(),
				new Brass(),
				new WoodWind()
		};
		tuneAll(instruments);
	}

	/**
	 * 有多态带来的特性，
	 * 我们给instruments数组增加元素，也会继续正常运行，不会出现问题。
	 *
	 * @param i
	 */
	public static void tune(Instrument i) {
		i.play();
	}

	public static void tuneAll(Instrument[] instruments) {
		for (Instrument instrument : instruments) {
			tune(instrument);
		}
	}
}